<template>
	<view class="content">
		<view style="height: 30rpx;"></view>
		<view class="wid90 mar bacFFF borRad20" style="min-height: calc(100vh - 80rpx);">
			<view style="height: 20px;"></view>
			<view class="wid90 mar">
				<view class="hei80 dis disAl foSi40" style="font-weight: 600;">{{list.title}}</view>
				<view class="dis disAl disJuB mar-top20 hei80">
					<view style="color: #939495;" class="foSi20">更新于 {{list.createtime}}</view>
					<view class="dis foSi25">
						<view class="dis disAl" @click="shouchang">
							<image src="../../static/index/shouchang.png" style="width: 50rpx;height: 50rpx;"></image>
							<view class="mar-left10">收藏</view>
						</view>
						<button class="dis disAl mar-left20 foSi25" style="background-color: #fff;" type="default" data-name="shareBtn" open-type="share"> 
							<image src="../../static/index/fenxiang.png" style="width: 50rpx;height: 50rpx;"></image>
							<view class="mar-left10">分享</view>
						</button>
					</view>
				</view>
				<view style="height: 10rpx;"></view>
				 <!-- style="min-height: 100vh - 20px;" -->
			</view>
			<view class="wid95 mar xhx"></view>
			<view class="wid90 mar">
				<view style="height: 30rpx;"></view>
				<rich-text :nodes="list.content"></rich-text>
				<view style="height: 30rpx;"></view>
			</view>
			
		</view>
		<view style="height: 50rpx;"></view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: '',
				id: '',
				url: this.global.url
			}
		},
		onLoad(options) {
			this.id = options.id
			this.getList()
			uni.showShareMenu({
				withShareTicket: true,
				menus: ["shareAppMessage", "shareTimeline"]
			})
		},
		onShareAppMessage(res) {
			let that = this;
			let imageUrl = that.url+that.list.coverimg || '';
			return {
				title: that.title,
				path: '/pages/video/particulars?id'+that.id,
				imageUrl: imageUrl
			};
		},
		// 分享到朋友圈
		onShareTimeline() {
			let that = this;
			let imageUrl = that.url+that.list.coverimg || '';
			return {
				title: that.title,
				path: '/pages/video/particulars?id'+that.id,
				imageUrl: imageUrl
			};
		},
		methods: {
			shouchang(){
				var that = this
				uni.request({
				    url: that.global.url + 'api/classroom/coll',
				    method: "POST",
					header: {
						'token': uni.getStorageSync('token')
					},
				    data: {
						cid: this.id
					},
				    success(res) {
				        let result = res.data
				        if(result.code == 1){
							uni.showToast({
								title: result.msg,
							})
						}else{
							uni.showToast({
								title: result.msg,
								icon: 'error'
							})
				        }
				       
				    }
				})
			},
			getList(){
				var that = this
				uni.request({
				    url: that.global.url + 'api/classroom/details',
				    method: "POST",
					header: {
						'token': uni.getStorageSync('token')
					},
				    data: {
						id: this.id
					},
				    success(res) {
				        let result = res.data
				        if(result.code == 1){
							that.list = result.data
							that.list.content = that.formatGoodsData(that.list.content)
						}else{
				           uni.showToast({
				           	title: result.msg,
				           	icon: 'error'
				           })
				        }
				       
				    }
				})
			},
			formatGoodsData(data) {
				return data.replace(/width:[^;]+;/gi, 'width: 100%;')
			}
		}
	}
</script>

<style>
	.content {
		min-height: 100vh;
		background-color: #F0F0F0;
	}
	button::after {
		border: none;
	}
	button {
		background-color: #fff;
		border-radius:0;
		padding: 0;
		margin: 0;
	}
</style>
